Ext.define('appfe.stockor.exec.form.ExecHoldEditForm', {
    extend: 'Ext.form.Panel',
    alias: 'widget.stockor.exec.form.ExecHoldEditForm',
    requires: [
        'appfe.stockor.exec.form.ExecHoldEditFormController'
    ],
    controller: 'stockor.exec.form.ExecHoldEditForm',
    viewModel: {
        type: 'stockor.exec.ExecHold',//继承这个model, 同时下面有自己的个性化的定义
        data: {
            submitButtonText: '', //提交按钮文本
            actionType: 'insert', //insert. update.delete
            parentItemId: '',
            isValidSlimsymbol: false,
            // 表单信息
            holdStock: {
                slimsymbol: '',
                stkName: '',
                holdVolume: '',
                unitCost: '',
                status: '',
                comments: ''
            }
        },
        formulas: {
            submitBtnText: {
                bind: {
                    bindTo: '{actionType:lowercase}',
                    deep: true
                },
                get: function (actionType) {
                    return actionType == 'update' ? '提交更新' : '提交新建';
                }
            },
            updateAction: {
                bind: {
                    bindTo: '{actionType:lowercase}',
                    deep: true
                },
                get: function (actionType) {
                    if (actionType == 'update') {
                        return true;
                    } else {
                        return false;
                    }
                }
            },
            totalCost: function (get) {
                return Ext.util.Format.number(get('holdStock.unitCost') * get('holdStock.holdVolume'), '￥0.00');
            }
        }
    },

    ui: 'won-form',
    autoScroll: true,
    buttonAlign: 'center',
    bodyPadding: 10,
    fieldDefaults: {
        labelAlign: 'right',
        labelWidth: 90
    },
    defaults: {
        // width: 600,
        labelWidth: 120,
        labelAlign: 'right',
        anchor: '90%',
        resizable: true,
        grow: true,
        allowBlank: false
    },
    items: [
        { xtype: 'hidden', name: 'slimsymbol', bind: '{holdStock.slimsymbol}' },
        {
            xtype: 'textfield',
            name: 'symbol',
            fieldLabel: '股票简码',
            afterLabelTextTpl: ['<span style="color:red;font-weight:bold" data-qtip="必填项">*</span>'],
            emptyText: '',
            validationEvent: 'blur',
            regex: /^(([s]{1}[z]{1}[30]{1})|([s]{1}[h]{1}[6]{1}))(\d{5})$/, //([s]{1}[z]{1}[3]{1})|([s]{1}[h]{1}[6]{1})
            regexText: '参数不合法(必须以sh6或sz3开头,后接数字5位)!',/* 验证错误之后的提示信息 */
            bind: {
                value: '{holdStock.slimsymbol}',
                disabled: '{updateAction}' // 更改操作不允许修改
            },
            listeners: {
                blur: 'trimTxtOnBlur'
            }
        }, {
            xtype: 'displayfield',
            name: 'name',
            fieldLabel: '股票名称',
            bind: '{holdStock.stkName}'
        }, {
            xtype: 'numberfield',
            fieldLabel: '持仓数量',
            afterLabelTextTpl: ['<span style="color:red;font-weight:bold" data-qtip="必填项">*</span>'],
            name: 'holdVolume',
            allowDecimals: false,
            bind: '{holdStock.holdVolume}'
        }, {
            xtype: 'numberfield',
            fieldLabel: '每股成本(￥)',
            afterLabelTextTpl: ['<span style="color:red;font-weight:bold" data-qtip="必填项">*</span>'],
            name: 'unitCost',
            decimalPrecision: 2,//这里设置保留小数位数
            bind: '{holdStock.unitCost}'
        }, {
            xtype: 'displayfield',
            name: 'totalCost',
            fieldLabel: '总成本',
            bind: {
                value: '{totalCost}'
            }
        }, {
            xtype: 'combo',
            name: 'status',
            fieldLabel: '状态',
            editable: false,
            allowBlank: false,
            blankText: '状态选择不能为空',
            emptyText: '请选择状态',
            queryMode: 'local',
            displayField: 'code',
            valueField: 'code',
            bind: {
                store: '{execHoldStatusStore}',
                value: '{holdStock.status}'
            },
            triggerAction: 'all',
            flex: 1,
            listConfig: {
                itemTpl: ['<div data-qtip="{text}: {tip}">{code}</div>']
            }
        }, {
            xtype: 'textareafield',
            name: 'comments',
            fieldLabel: '备注',
            bind: {
                value: '{holdStock.comments}'
            },
            autoHeight: true,
            allowBlank: true
        }

    ],
    buttons: [
        { // 提交按钮
            xtype: 'buttongreen',
            formBind: true,
            handler: 'submitForm',
            iconCls: 'x-fa fa-plus white-fontawesome-icon',
            bind: {
                text: '{submitBtnText}',
                disabled: '{updateAction}' // 更改操作不允许修改
            }
        }
    ],
    listeners: {
        // afterrender: 'afterrender'
    }
});